import {
	dqUrl,
	trUrl,
	trUrltest
} from "../baseUrl.js";

const orderpGet = function(url) {
	return function(params) {
		return new Promise((resolve, reject) => {
			let userInfo = uni.getStorageSync('userInfo')
			const Authorization = (userInfo && userInfo.token) || ''
			uni.request({
				url: dqUrl + url,
				method: 'get',
				header: {
					Authorization
				},
				data: params,
				success: res => {
					// console.log('*********GET-orderp请求: ', res)
					if (url === '/api/user/update/icon') {
						resolve(res)
					} else if (res && res.data.code == 200) {
						resolve(res.data.data)
					} else {
						reject(res)
					}
				},
				fail: err => {
					console.log(err)
					reject(err)
				}
			})
		})
	}
};

const orderpPost = function(url) {
	return function(params) {
		return new Promise((resolve, reject) => {
			let userInfo = uni.getStorageSync('userInfo')
			const Authorization = (userInfo && userInfo.token) || ''
			uni.request({
				url: dqUrl + url,
				method: 'post',
				header: {
					Authorization
				},
				data: params,
				success: res => {
					// console.log('*********POST-orderp请求: ', res)
					if (url === '/api/user/forget/pd') {
						resolve(res)
					} else if (url === '/api/user/update/pd') {
						resolve(res)
					} else if (url === '/api/user/loginByMobile') {
						resolve(res)
					} else if (url === '/api/urban/commitQuestion') {
						resolve(res)
					} else if (res && res.statusCode === 200) {
						if (res.data.success) {
							resolve(res.data.data)
						} else {
							reject(res.data)
						}
					} else {
						reject(res.data)
					}
				},
				fail: err => {
					console.log(err)
					reject(err)
				}
			})
		})
	}
};
const orderpPosttd = function(url) {
	return function(params) {
		return new Promise((resolve, reject) => {
			let userInfo = uni.getStorageSync('userInfo')
			const Authorization = (userInfo && userInfo.token) || ''
			uni.request({
				url: trUrl + url,
				method: 'post',
				header: {
					Authorization
				},
				data: params,
				success: res => {
					// console.log('*********POST-orderp请求: ', res)
					if (url === '/api/user/forget/pd') {
						resolve(res)
					} else if (url === '/api/user/update/pd') {
						resolve(res)
					} else if (url === '/api/user/loginByMobile') {
						resolve(res)
					} else if (url === '/api/urban/commitQuestion') {
						resolve(res)
					} else if (res && res.statusCode === 200) {
						if (res.data.success) {
							resolve(res.data.data)
						} else {
							reject(res.data)
						}
					} else {
						reject(res.data)
					}
				},
				fail: err => {
					console.log(err)
					reject(err)
				}
			})
		})
	}
};
const uploadUrl = dqUrl + '/api/upload/minio'
const getOrgUserListUrl = dqUrl + '/api/user/list'

export {
	orderpGet,
	orderpPost,
	uploadUrl,
	getOrgUserListUrl,
	orderpPosttd
}
